﻿@model IEnumerable<Models.CMS_Keyword>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="description" content="Crush it Able The most popular Admin Dashboard template and ui kit">
    <meta name="author" content="PuffinTheme the theme designer">

    <link rel="icon" href="~/Crushit/light/favicon.ico" type="image/x-icon" />

    <title>:: Crush it :: Table Normal</title>

    <!-- Bootstrap Core and vandor -->
    @*<link rel="stylesheet" href="http://cdn.bootstrapmb.com/bootstrap/4.3.1/css/bootstrap.min.css" />*@

    <!-- Core css -->
    <link rel="stylesheet" href="/Crushit/assets/css/main.css" />
    <link rel="stylesheet" href="/Crushit/assets/css/theme4.css" id="stylesheet" />
    <style>

        button {
            background-color: #CCE8EB; /* Green */
            border: none;
            color: #666;
            /*padding: 15px 32px;*/
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            border: 1px solid #cad9ea;
        }

        #table {
            margin-left: 22%;
            font-size: 14px;
            width: 79%;
            border-collapse: collapse;
            text-align: center;
        }

            #table td, table th {
                border: 1px solid #cad9ea;
                color: #666;
                height: 30px;
            }

        table thead th {
            background-color: #CCE8EB;
            width: 100px;
        }

        table tr:nth-child(odd) {
            background: #fff;
        }

        table tr:nth-child(even) {
            background: #F5FAFA;
        }
    </style>
</head>
<body>
    <div class="card-body">
        <div class="table-responsive">
            @*<label>开始时间：</label><input type="datetime-local" id="cmtime" />*@
            <label>关键字：</label><input type="text" id="keyword" /> <button onclick="Select()">查询</button>
            @Html.ActionLink("添加关键字", "AddCMS_Keyword")

            <table id="table">
                <thead>
                    <tr>
                        <th>编号</th>
                        <th _msthash="5072223" _msttexthash="4389879">关键字</th>
                        <th _msthash="5072353" _msttexthash="2092545">搜索次数</th>
                        <th _msthash="5072483" _msttexthash="7861633">最后一次搜索时间</th>
                        <th _msthash="5072483" _msttexthash="7861633">是否显示</th>
                        <th _msthash="5072483" _msttexthash="7861633">操作</th>
                    </tr>
                </thead>
                <tbody>
                    @*@foreach (var item in Model)
                {
                    <tr>
                        <td>@item.aid</td>
                        <th scope="row" _msthash="5079971" _msttexthash="4459">@item.aid</th>
                        <td>@item.title</td>
                        <td _msthash="5079686" _msttexthash="5761756">@item.title</td>
                        <td>@item.nname</td>
                        <td _msthash="5079816" _msttexthash="4700839">@item.nname</td>
                        <td>@item.cmtime</td>
                        <td _msthash="5079816" _msttexthash="4700839">@item.cmtime</td>
                        <td>@item.cmhtml</td>
                        <td _msthash="5079816" _msttexthash="4700839">@item.cmhtml</td>
                        <td>修改 删除</td>
                    <td _msthash="5079816" _msttexthash="4700839">
                        @Html.ActionLink("修改", "GetView_CommentAU", "Index", new { aid = item.aid })
                        @Html.ActionLink("删除", "GetView_CommentAU", "Index", new { aid = item.aid })
                    </td>
                    </tr>
                }*@

                </tbody>
            </table>
            <label id="page">当前第几页共几页</label>
            <div id="rightPage">
                <button onclick="first()">首页</button><button onclick="prve()">上一页</button><button onclick="next()">下一页</button><button onclick="last()">尾页</button>
                转到第<input type="number" size="1" id="Page" style="width:50px;" />页&nbsp;
                <button onclick="toPage()">跳转</button>
            </div>
        </div>
    </div>
    <script src="/Crushit/assets/bundles/lib.vendor.bundle.js"></script>
    <script src="/Crushit/assets/js/core.js"></script>
    @*}*@

    <script>
@*$(function () {
            $.ajax({
                url: "@Url.Action("GetView_CommentAU")",
                datatype: 'json',
                type: "get",
                data: { /*pageindex: 1, pagesize:5*/},
                success: function (data) {
                    dataShow(data.d.Data);
                    alert(data.d.Data);
                    $('#example').bootstrapPaginator(Getoptions(JSON.parse(data)));
                    //BootstrapPaginator($('#example'),Getoptions(JSON.parse(data)));
                },
                error: function () { }
            });
            var myModal = new bootstrap.Modal(document.getElementById('staticBackdrop'));
            console.log(myModal);
            $("#sel").click(function () {
                $.post("@Url.Action("GetView_CommentAU")",
                    {
                        //pageindex: 1,
                        //pagesize: 5,
                        "aid": $("#aid").val(),
                    }, function (data) {
                    dataShow(data);
                    $('#example').bootstrapPaginator(Getoptions(JSON.parse(data)));
                });
            });
            $("#add").click(function () {
                //可以不用定义全局
                //var myModalEl = document.getElementById('staticBackdrop')
                //var modal = bootstrap.Modal.getInstance(myModalEl)
                //console.log(modal);
                //modal.hide();
                //myModal.hide()
                console.log(myModal);
                myModal.toggle();

            });
        })
        //表格显示数据
        function dataShow(r) {
            $(".table tr:gt(0)").remove();
            if (r != null) {
                $.each(eval("(" + r + ")").list, function (index, item) { //遍历返回的json
                    var tr = $("<tr>").appendTo(".table");
                    $("<td>").text(item.aid).appendTo(tr);
                    $("<td>").text(item.cid).appendTo(tr);
                    $("<td>").text(item.title).appendTo(tr);
                    $("<td>").text(item.author).appendTo(tr);
                    $("<td>").text(item.uid).appendTo(tr);
                    $("<td>").text(item.ctime).appendTo(tr);
                    //$("<td>").appendTo(tr).text(item.ptime);
                    //if (item.state == 1) {
                    //    $("<td>").appendTo(tr).text("草稿");
                    //} else if (item.MZ == 2) {
                    //    $("<td>").appendTo(tr).text("发布");
                    //}
                    //$("<td>").appendTo(tr).text(item.hits);
                    //$("<td>").appendTo(tr).text(item.comments);
                    //$("<td>").appendTo(tr).text(item.ahtml);
                });
            }
        }
        //显示分页插件的数据
        function Getoptions(r) {
            return {
                currentPage: r.currentPage, //当前页数
                totalPages: r.pageSum, //总页数
                itemTexts: function (type, page, current) {
                    switch (type) {
                        case "first":
                            return "首页";
                        case "prev":
                            return "上一页";
                        case "next":
                            return "下一页";
                        case "last":
                            return "末页";
                        case "page":
                            return page;
                    }
                },//点击事件，用于通过Ajax来刷新整个list列表
                onPageClicked: function (event, originalEvent, type, page) {
                    $.post("@Url.Action("GetView_CommentAU")",
                        {
                            pageindex: page,
                            pagesize: 5,
                            "aid": $("#aid").val(),
                            //"sex": $("input[name='sex']:checked").val()
                        }, function (r) {
                        dataShow(r);
                    });
                }
            }
        }*@</script>

    <script>
        var PageIndex = 1;
        var pageSize = 3;
        var PageAll = 1;
       // var
        window.onload = SelectCMS_Keyword();

        function SelectCMS_Keyword() {
                /*var time = $("#cmtime").val();*/
                var keyword = $("#keyword").val();
                //alert(pageSize);
            $.ajax({
                type: "post",
                url: "@Url.Action("GetCMS_Keyword")",
                data: JSON.stringify({ PageIndex: PageIndex, PageSize: pageSize, keyword: keyword }),
                datatype: 'json',
                contentType: "application/json",
                success: function (rs) {
                    //alert(rs.Count);
                    //alert(time + "aa" + html);
                    PageAll = Math.ceil(rs.Count / pageSize);
                    $("#page").text("共有" + PageAll + "页，当前第" + PageIndex + "页");
                    var table = $("#table");
                    table.find("tr:gt(0)").remove();
                    $.each(rs.Data, function (index, e) {
                        var tr = $("<tr/>");
                        var tds = $("<td/><td/><td/><td/><td/><td/>");
                        tds.eq(0).text(e.kid);
                        tds.eq(1).text(e.keyword);
                        tds.eq(2).text(e.stimes);
                        var hm = parseFloat(e.ltimes.substr(6));
                        //将毫秒数转换成正常的格式时间
                        var d = new Date(hm);
                        //tds.eq(3).text(d.toLocaleDateString());
                        tds.eq(3).text(d.toLocaleDateString());
                        if (e.show) {
                            tds.eq(4).text("是");
                        } else {
                            tds.eq(4).text("否");
                        }

                        /*<a onclick='update(" + e.cmid + ")'>修改</a> & nbsp;*/
                        tds.eq(5).html("<a onclick='update(" + e.kid + ")'>修改</a> &nbsp;<a onclick='DeleteID(" + e.kid + ")'>删除</a>");
                        tr.append(tds);
                        table.append(tr);
                    })
                },
            });
        }
        //查询按钮
        function Select() {
            SelectCMS_Keyword();
        }
        //首页
        function first() {
            PageIndex = 1;
            SelectCMS_Keyword();
        }
            //上一页
        function prve() {

            PageIndex = PageIndex - 1 < 1 ? 1 : PageIndex - 1;
            SelectCMS_Keyword();
        }
        //下一页
        function next() {
            PageIndex = PageIndex + 1 >= PageAll ? PageAll : PageIndex + 1;
            SelectCMS_Keyword();
        }
        //尾页
        function last() {
            PageIndex = PageAll;
            SelectCMS_Keyword();
        }
        //跳转到多少页
        function toPage() {
            //alert(PageIndex);
            var page = $("#Page").val();
            //alert(page);
            if (page > PageAll || page <= 0) {
                alert("该页数无法跳转，请重新输入！");
                return;
            } else {
                PageIndex = page;
                SelectCMS_Keyword();
            }
            }
            //删除
            function DeleteID(kid) {
                var bool = window.confirm("确定要删除吗？");
                if (bool) {
                    $.ajax({
                        type: "post",
                        url: "@Url.Action("DeleteCMS_Keyword")",
                        data: JSON.stringify({ kid: kid }),
                        datatype: 'json',
                        contentType: "application/json",
                        success: function (rs) {
                            //alert(cmid);
                            if (rs) {
                                alert("删除成功！");
                                SelectCMS_Keyword();
                            } else {
                                alert("删除失败！");
                            }
                },
            });
                }
        }
        //修改
        function update(kid) {
             @*$.ajax({
                        type: "get",
                        url: "@Url.Action("UpdateCMS_Keyword")",
                        data: JSON.stringify({ kid: kid }),
                        //datatype: 'json',
                        //contentType: "application/json",
                 success: function (rs) {
                     window.location.href = "@Url.Action("Index", "UpdateCMS_Keyword")";
                },
            })*@
            window.location.href = "https://localhost:44347/HouTaiArea/Index/UpdateCMS_Keyword?kid=" + kid;
        }
    </script>
</body>
